<template>

	<div class="header">
		<div class="header_left"><p>专家管理平台</p></div>
		<div class="header_right">
			<p>用户角色：</p>
			<div>
				<el-select v-model="value" placeholder="请选择"
				@change="changeVal">
					<el-option
					v-for="item in userInfo.option"
					:key="item.value"
					:label="item.label"
					:value="item.value"
					>
					</el-option>
				</el-select>
			</div>


		</div>
	</div>
</template>
<script>
import { userInfo } from "../../http/api";
export default {
  name: "HeaderComponent",
  data() {
    return {
      value: null,

      timeNum: 0,
      isDisabled: false,
      userInfo: ``,
      timeUser: null
      // option:null
    };
  },
  created() {
    let that = this;
    // 获取本地存储
    that.getUserInfo();
    // that.toggle()
  },

  methods: {
    getUserInfo() {
      let that = this;
      console.log(`获取本地用户数据>>>>>>>>>>>>>>>>>>>>`, that.timeNum);
      // 如果调用了10次就不执行
      if (that.timeNum === 10) {
        console.log(`return`);
        return false;
      } else {
        // 每300毫秒执行一次读取数据
        that.timeUser = setTimeout(() => {
          if (!that.userInfo) {
            that.timeNum++;
            let userInfo = JSON.parse(window.localStorage.getItem("userInfo"));
            if (userInfo) {
              console.log(`已取到用户数据>>>>>>>>>>>>>>>>>>>>`);
              that.userInfo = userInfo;
              this.value = that.userInfo.option[0].value;
              clearInterval(that.timeUser);
            } else {
              that.getUserInfo();
            }
          }
        }, 300);
      }
    },

    changeVal(val) {
      console.log(`看看我选中的是什么`, val);
      if (val === "管理员") {
        this.userInfo.navList = this.$store.state.childRouter.manager;
				 let name= this.userInfo.navList[0].name
        this.$store.commit(`getInfoData`, this.userInfo);
        window.sessionStorage.setItem(`routerName`, name);
        this.$router.push({
          name: this.userInfo.navList[0].name // 第一个路由
        });

        console.log(`userInfo`, this.userInfo);
      } else {
        this.userInfo.navList = this.$store.state.childRouter.expert;
				let name= this.userInfo.navList[0].name
        this.$store.commit(`getInfoData`, this.userInfo);
        window.sessionStorage.setItem(`routerName`, name);
        this.$router.push({
          name: this.userInfo.navList[0].name // 第一个路由
        });
      }
    }
  }
};
</script>
<style>
.header {
  width: 100%;
  height: 80px;
  display: flex;
  align-items: center;
}
.header_left {
  width: 50%;
}
.header_right {
  width: 50%;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  /* justify-content: center; */
}
</style>
